package com.jxk.security.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jxk.security.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jxk
 * @since 2020-10-25
 */
public interface UserMapper extends BaseMapper<User> {
    //根据userID查询用户角色
    @Select("SELECT r.name\n" +
            "FROM role r\n" +
            "LEFT JOIN ur ON r.id = ur.rid\n" +
            "LEFT JOIN user u ON u.id = ur.uid\n" +
            "WHERE u.name = #{name}")
    List<String> findRoleByUserName( String name);
    @Select({
            "<script>",
            "SELECT p.url " ,
            "FROM permition p " ,
            "LEFT JOIN rp ON p.id = rp.pid " ,
            "LEFT JOIN role r ON r.id = rp.rid ",
            "WHERE r.name IN ",
            "<foreach collection='roleCodes' item='roleCode' open='(' separator=',' close=')'>",
            "#{roleCode}",
            "</foreach>",
            "</script>"
    })
    List<String> findAuthorityByRoleCodes(@Param("roleCodes") List<String> roleCodes);
}
